package com.aerozhonghuan.archive.controller;

import com.aerozhonghuan.archive.dto.DeletionResult;
import com.aerozhonghuan.archive.service.DataDeletionService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/api/data-deletion")
public class DataDeletionController {

    private final DataDeletionService dataDeletionService;

    public DataDeletionController(DataDeletionService dataDeletionService) {
        this.dataDeletionService = dataDeletionService;
    }

    /**
     * 执行数据删除操作
     *
     * @param baseDate 时间格式 "yyyy-MM-dd HH:mm:ss"
     * @param batchSize 每次删除批次大小，默认 10000
     */
    @PostMapping("/execute")
    public List<DeletionResult> executeDeletion(
            @RequestParam("baseDate")
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date baseDate,
            @RequestParam(value = "batchSize", defaultValue = "10000") int batchSize) {
        return dataDeletionService.executeDeletion(baseDate, batchSize);
    }
}
